import Vue from 'vue'  //引入Vue文件
import autoTextarea from '@/components/common/textarea'

Vue.directive('growHeight', {   //自定义一个文本框自适应高度
  componentUpdated: function (el, bonding) {
    const grow = el.getAttribute('data-grow');
    if (grow === 'false') {
      autoTextarea(el, bonding.value);
      el.setAttribute('data-grow', 'true');
    }
  },
  inserted: function (el, bonding) {
    autoTextarea(el, bonding.value);
    el.setAttribute('data-grow', 'false');
  },
});
// 自定义一个指令实现点击别处下拉框消失
 Vue.directive('clickoutside', {
 bind: function(el, binding, vode) {
  function documentHandler (e) {
   if (el.contains(e.target)) {
    return false
   }
   if (binding.expression) {
    binding.value(e)
   }
  }
  el.__vueClickOutSide__ = documentHandler
  document.addEventListener('click', documentHandler)
 },
 unbind: function(el, binding) {
  document.removeEventListener('click', el.__vueClickOutSide__)
  delete el.__vueClickOutSide__
 }
})
